{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "866ac389",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "# import igraph as ig\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import math\n",
    "import time\n",
    "import datetime,time\n",
    "import os\n",
    "import pickle\n",
    "pd.set_option('display.max_info_columns', 500)\n",
    "pd.set_option('display.max_columns', 1000)\n",
    "pd.set_option('display.max_row', 300)\n",
    "pd.set_option('display.float_format', lambda x: ' %.5f' % x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ad02f9b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 展开数据集列表\n",
    "os.listdir('../../../contest/train')\n",
    "os.listdir('../../../contest/B')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0369cb21",
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_all_csv(path):\n",
    "    return read_all_csv_(path)\n",
    "    \n",
    "def read_all_csv_(path):\n",
    "    data_dict = {}\n",
    "    # print(\"根目录\"+os.getcwd())\n",
    "    for root, ds, fs in os.walk(path):\n",
    "        # print(root)\n",
    "        for f in fs:\n",
    "            if f.endswith('.csv'):\n",
    "                # print(f)\n",
    "                fullname = os.path.join(root, f)\n",
    "                # 去除文件名后缀\n",
    "                data_name = os.path.splitext(f)[0]\n",
    "                data_dict[data_name] = pd.read_csv(fullname)\n",
    "                print(\"读取: \"+fullname)\n",
    "                print(data_dict[data_name].shape)\n",
    "                # \n",
    "    if len(data_dict) == 0:\n",
    "        raise ValueError(\"路径有误, csv文件不存在\")\n",
    "    else:\n",
    "        print(\"文件列表如下:\")\n",
    "        print(data_dict.keys())\n",
    "    return data_dict   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e5fedf4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取数据集\n",
    "df_train = read_all_csv('../../../contest/train/')\n",
    "print(\"------------------------------------------------\")\n",
    "df_train = read_all_csv('../../../contest/B/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea30425d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自然属性处理\n",
    "\n",
    "# 性别转化\n",
    "def sex_binning(x):\n",
    "    if x == 'A':\n",
    "        return 1\n",
    "    elif x == 'B':\n",
    "        return 2\n",
    "    else:\n",
    "        return np.nan\n",
    "df_train['nature_NTRL_CUST_SEX_CD'] = df_train['nature_NTRL_CUST_SEX_CD'].apply(lambda x: sex_binning(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f7df561",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 客户等级转化\n",
    "def rank_binning(x):\n",
    "    if x == 'A':\n",
    "        return 1\n",
    "    elif x == 'B':\n",
    "        return 2\n",
    "    elif x == 'C':\n",
    "        return 3\n",
    "    elif x == 'D':\n",
    "        return 4\n",
    "    elif x == 'E':\n",
    "        return 5\n",
    "    elif x == 'F':\n",
    "        return 6\n",
    "df_train['nature_NTRL_RANK_CD'] = df_train['nature_NTRL_RANK_CD'].apply(lambda x: rank_binning(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5a0f50c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 金额还原\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a1ee59c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 空值处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62804667",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 异常值处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "92ecaa31",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
